package at.tasat.test.levelx;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import at.tasat.Main;
import at.tasat.test.level3.DimacsFuzzer;

public final class QueueSpeedtest {

	private static final String[] ARGUMENTS = { "--queue=default", "--queue=inverting", "--queue=dynamic-occurences", "--queue=static-occurences", "--queue=random --seed=0",
			"--queue=random --seed=42", "--queue=random --seed=1000", "--queue=random --seed=424242" };

	public static void main(String[] _) throws IOException {
		String str = DimacsFuzzer.getRandomCnf(150, 3000);

		File file = File.createTempFile("QueueSpeedTest_", ".cnf");
		BufferedWriter writer = new BufferedWriter(new FileWriter(file));
		BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(str.getBytes())));
		for (String line = reader.readLine(); line != null; line = reader.readLine()) {
			writer.write(line);
			writer.write('\n');
		}
		writer.close();
		reader.close();

		for (int i = 0; i < ARGUMENTS.length; i++) {
			String argument = ARGUMENTS[i];
			System.out.println("Executing with arguments " + argument);
			String[] argumentArray = argument.split(" ");
			String[] args = Arrays.copyOf(argumentArray, argumentArray.length + 1);
			args[args.length - 1] = file.getAbsolutePath();
			long startTime = System.currentTimeMillis();
			Main.main(args);
			long time = System.currentTimeMillis() - startTime;
			System.out.println("needed " + time + "[ms]");
		}
	}

}
